home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsdll.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.7 KB  |  224 lines

  1. /* Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18. /* Portions Copyright (C) 1994, 1995, 1996, Russell Lang.  All rights reserved. */
  19.  
  20.  
  21. /*$Id: gsdll.c,v 1.3 2000/09/19 19:00:27 lpd Exp $ */
  22. /* Dynamic Link Library interface for OS/2 and MS-Windows Ghostscript */
  23. /* front end to gs.c */
  24.  
  25. /* HOW MANY OF THESE INCLUDES ARE REALLY NEEDED? */
  26.  
  27. #include "ctype_.h"
  28. #include "memory_.h"
  29. #include <stdarg.h>
  30. #include "string_.h"
  31.  
  32. #include "ghost.h"
  33. #include "gscdefs.h"
  34. #include "gxdevice.h"
  35. #include "gxdevmem.h"
  36. #include "stream.h"
  37. #include "errors.h"
  38. #include "estack.h"
  39. #include "ialloc.h"
  40. #include "ivmspace.h"
  41. #include "sfilter.h"        /* for iscan.h */
  42. #include "ostack.h"        /* must precede iscan.h */
  43. #include "iscan.h"
  44. #include "main.h"
  45. #include "imainarg.h"
  46. #include "store.h"
  47. #include "files.h"        /* requires stream.h */
  48. #include "interp.h"
  49.  
  50. /*
  51.  * The following block of platform-specific conditionals is contrary to
  52.  * Ghostscript's portability policy.  It is here because it doesn't
  53.  * represent any useful abstraction, so isn't a good candidate for
  54.  * encapsulation in a header file either.
  55.  */
  56.  
  57. #ifdef _Windows
  58. #include "windows_.h"
  59. #ifndef __WIN32__
  60. #define GSDLLEXPORT _export
  61. #endif
  62. #else  /* !_Windows */
  63.  
  64. #ifdef __OS2__
  65. #define INCL_DOS
  66. #define INCL_WIN
  67. #include <os2.h>
  68. #else  /* !__OS2__ */
  69.  
  70. #ifdef __MACINTOSH__
  71. /* Nothing special for the Mac. */
  72. #endif  /* !__MACINTOSH__ */
  73.  
  74. #endif  /* !__OS2__ */
  75.  
  76. #endif  /* !_Windows */
  77.  
  78. /*
  79.  * End of platform-specific conditionals.
  80.  */
  81.  
  82. #include "gsdll.h"        /* header for DLLs */
  83. #include <setjmp.h>
  84.  
  85. jmp_buf gsdll_env;        /* used by gp_do_exit in DLL configurations */
  86.  
  87. private int gsdll_usage;    /* should be needed only for 16-bit SHARED DATA */
  88.  
  89. /****** SINGLE-INSTANCE HACK ******/
  90. private gs_main_instance *gsdll_minst;    /* instance data */
  91. extern HWND hwndtext;        /* in gp_mswin.c, gp_os2.c, or gp_mac.c */
  92. GSDLL_CALLBACK pgsdll_callback;    /* callback for messages and stdio to caller */
  93.  
  94.  
  95. /* ---------- DLL exported functions ---------- */
  96.  
  97. /* arguments are:
  98.  * 1. callback function for stdio and for notification of 
  99.  *   sync_output, output_page and resize events
  100.  * 2. window handle, used as parent.  Use NULL if you have no window.
  101.  * 3. argc
  102.  * 4. argv
  103.  */
  104. int GSDLLAPI
  105. gsdll_init(GSDLL_CALLBACK callback, HWND hwnd, int argc, char GSFAR * argv[])
  106. {
  107.     int code;
  108.  
  109.     if (gsdll_usage) {
  110.     return GSDLL_INIT_IN_USE;    /* DLL can't be used by multiple programs under Win16 */
  111.     }
  112.     gsdll_usage++;
  113.  
  114.     if (setjmp(gsdll_env)) {
  115.     gsdll_usage--;
  116.     if (gs_exit_status)
  117.         return gs_exit_status;    /* error */
  118.     return GSDLL_INIT_QUIT;    /* not an error */
  119.     }
  120. /****** SINGLE-INSTANCE HACK ******/
  121.     pgsdll_callback = callback;
  122.     hwndtext = hwnd;
  123.  
  124. /****** SINGLE-INSTANCE HACK ******/
  125.     gsdll_minst = gs_main_instance_default();
  126.  
  127.     /* in gs.c */
  128.     code = gs_main_init_with_args(gsdll_minst, argc, argv);
  129.     if (code < 0) {
  130.     gsdll_usage--;
  131.     return code;
  132.     }
  133.  
  134.     return 0;
  135. }
  136.  
  137. /* if return value < 0, then error occured and caller should call */
  138. /* gsdll_exit, then unload library */
  139. int GSDLLAPI
  140. gsdll_execute_begin(void)
  141. {
  142.     int exit_code;
  143.     ref error_object;
  144.     int code;
  145.  
  146.     if (!gsdll_usage)
  147.     return -1;
  148.     if (setjmp(gsdll_env))
  149.     return gs_exit_status;    /* error */
  150.     code = gs_main_run_string_begin(gsdll_minst, 0, &exit_code, &error_object);
  151.     return code;
  152. }
  153.  
  154. /* if return value < 0, then error occured and caller should call */
  155. /* gsdll_execute_end, then gsdll_exit, then unload library */
  156. int GSDLLAPI
  157. gsdll_execute_cont(const char GSFAR * str, int len)
  158. {
  159.     int exit_code;
  160.     ref error_object;
  161.     int code;
  162.  
  163.     if (!gsdll_usage)
  164.     return -1;
  165.     if (setjmp(gsdll_env))
  166.     return gs_exit_status;    /* error */
  167.     code = gs_main_run_string_continue(gsdll_minst, str, len, 0, &exit_code, &error_object);
  168.     if (code == e_NeedInput)
  169.     code = 0;        /* this is not an error */
  170.     return code;
  171. }
  172.  
  173. /* if return value < 0, then error occured and caller should call */
  174. /* gsdll_exit, then unload library */
  175. int GSDLLAPI
  176. gsdll_execute_end(void)
  177. {
  178.     int exit_code;
  179.     ref error_object;
  180.     int code;
  181.  
  182.     if (!gsdll_usage)
  183.     return -1;
  184.     if (setjmp(gsdll_env))
  185.     return gs_exit_status;    /* error */
  186.     code = gs_main_run_string_end(gsdll_minst, 0, &exit_code, &error_object);
  187.     return code;
  188. }
  189.  
  190. int GSDLLAPI
  191. gsdll_exit(void)
  192. {
  193.     if (!gsdll_usage)
  194.     return -1;
  195.     gsdll_usage--;
  196.  
  197.     if (setjmp(gsdll_env))
  198.     return gs_exit_status;    /* error */
  199.     /* don't call gs_exit() since this would cause caller to exit */
  200.     gs_finit(0, 0);
  201.     pgsdll_callback = (GSDLL_CALLBACK) NULL;
  202.     return 0;
  203. }
  204.  
  205. /* return revision numbers and strings of Ghostscript */
  206. /* Used for determining if wrong GSDLL loaded */
  207. /* this may be called before gsdll_init */
  208. int GSDLLAPI
  209. gsdll_revision(char GSFAR ** product, char GSFAR ** copyright,
  210.            long GSFAR * revision, long GSFAR * revisiondate)
  211. {
  212.     if (product)
  213.     *product = (char *)gs_product;
  214.     if (copyright)
  215.     *copyright = (char *)gs_copyright;
  216.     if (revision)
  217.     *revision = gs_revision;
  218.     if (revisiondate)
  219.     *revisiondate = gs_revisiondate;
  220.     return 0;
  221. }
  222.  
  223. /* end gsdll.c */
  224.